/*
 * Generates a random weapon
 */

package item.weapon;

import java.util.Random;

public class RandomWeapon {
	
	//generates a random weapon based on level;
	
	public static Weapon random(int level) {
		
		Random r = new Random(); //number generator
		
		//generates properties
		
		//int condition = r.nextInt(100);
		int condition = 100;
		int weight = r.nextInt(10) + 5 * level;
		int numAttacks = r.nextInt(3) + 1 + level /10;
		int damage = (int) ((r.nextInt(20) + level * 15.0) / numAttacks + 100);
		int hitRate = (int) (r.nextInt(40) + 60 - numAttacks / 2.0);
		int range = r.nextInt(3) + 1;
		
		//randomly generates the weapon's damage type
		
		DamageType t;
		switch(r.nextInt(5)) {
			case 0:
				t = DamageType.ARMOR_PENETRATING;
				numAttacks = (int) (r.nextInt(3) + 1 + level / 15.0);
				damage = (int) ((r.nextInt(20) + level * 5.0) / numAttacks + 70);
				hitRate = (int) (r.nextInt(40) + 60 - numAttacks / 3.0);
				range = r.nextInt(3) + 1;
				if(r.nextInt(5) > 3)
					range += 2; //becomes a mass driver
				break;
			case 1:
				t = DamageType.PLASMA;
				numAttacks = (int) (r.nextInt(3) + 1 + level / 5.0);
				damage = (int) ((r.nextInt(20) + level * 5.0) / numAttacks + 70);
				hitRate = (int) (r.nextInt(40) + 60 - numAttacks / 3.0);
				range = r.nextInt(3) + 1;
				if(range > 1)
					range--;
				break;
			case 2:
				t = DamageType.LASER;
				numAttacks = (int) (r.nextInt(3) + 1 + level / 20.0);
				damage = (int) ((r.nextInt(20) + level * 5.0) / numAttacks + 70);
				hitRate = (int) (r.nextInt(40) + 60 - numAttacks / 3.0);
				range = r.nextInt(3) + 1;
				break;
			case 3:
				t = DamageType.MISSILE;
				numAttacks = (int) (r.nextInt(3) + 1 + level / 30.0);
				damage = (int) ((r.nextInt(20) + level * 3.0) / numAttacks + 70);
				hitRate = (int) (r.nextInt(40) + 60 - numAttacks / 3.0);
				range = r.nextInt(3) + 2;
				break;
			default:
				numAttacks = (int) (r.nextInt(3) + 1 + level / 10.0);
				damage = (int) ((r.nextInt(20) + level * 5.0) / numAttacks + 70);
				hitRate = (int) (r.nextInt(40) + 60 - numAttacks / 3.0);
				range = r.nextInt(3) + 1;
				t = DamageType.NONE;
		}//end of switch statement
		
		int cost = ((condition - weight * 3 + numAttacks * 10 + damage + hitRate + range * 10) * level) / 10; //status of properties determine price
		
		Weapon w = new Weapon(cost, condition, level, weight, t, damage, numAttacks, hitRate, range, 1);
		w.name = t.nameNomenclature;
		w.actionPoint = 2;
		if(r.nextInt(3) == 2)
			w.actionPoint = 3;
		return w;
	}//end of method Random

}//end of class RandomWeapon
